﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IFRS.Web;
using System.Data;
using IFRS.DataAccess.DAL;
using System.Globalization;
using System.Threading;
using IFRS.Models;
using IFRS_Global;
using vsm.CustomControl;

public partial class IFRS_WIN31_GL_INV_3V : PageBase
{
    #region "---------- Property -----------"

    public string Srcipt_SetValueGLAccount_GL = "";

    #endregion
    #region "---------- Events -----------"
    protected void Page_Load(object sender, EventArgs e)
    {
        Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US");
        if (!(Page.IsPostBack || Page.IsCallback))
        {
            this.ViewMenu();
            this.BindControlData();
            if (Request.QueryString["id"] != null)
            {
                this.BindData();
            }
            SetControl();
        }
        else
            ClientScript.RegisterHiddenField("isPostBack", "1");
    }

    protected void btnCANCEL_Click(object sender, EventArgs e)
    {
        Response.Redirect("~/IFRS/WIN31_1S.aspx");
    }
    #endregion
    #region "----- Methods -------"
    private void ViewMenu()
    {
        this.MenuTitleBar = Resources.ifrsMenu.WIN31_GL_LOT_4A;
    }

    private void BindControlData()
    {
        btnCANCEL.Attributes["OnClick"] = "if(!confirm(\"" + Resources.ifrsResource.ConfirmCancel + "\")) return false;";
    }
    private void SetControl()
    {
        SetControlReadOnly(form_control);
    }
    private void BindData()
    {
        if (Convert.ToString(Request.QueryString["id"]) != string.Empty)
        {

            var id = Convert.ToInt32(Request.QueryString["id"]);
            var dt = new SPR_GLACCOUNTPOSTING().SEARCH_BYID(id);
            if (dt != null && dt.Rows.Count > 0)
            {
                var list = new List<GLAccountPosting>();
                ConvertHelper.ConvertDataTableToObject(dt, list);

                txtGLGroup_ID.Text = list[0].GLGroup_NAME;
                hidGLAccountPostingID.Value = list[0].GLAccountPostingID.AsString();
                hidGLGroup_ID.Value = list[0].GLGroupID.AsString();
                hidGL_ACCOUNT.Value = list[0].GLAccountID.AsString();
                hidGL_ADJ_INT_INC_PL.Value = list[0].GL_ADJ_INT_INC_PL_ID.AsString();
                hidGL_ADJ_FV_BS.Value = list[0].GL_ADJ_FV_BS_ID.AsString();
                hidGL_ADJ_INT_INC_ELCLS_PL.Value = list[0].GL_ADJ_INT_INC_ELCLS_PL_ID.AsString();
                hidGL_ADJ_CST_BS.Value = list[0].GL_ADJ_CST_BS_ID.AsString();
                hidGL_REV_CST_PL.Value = list[0].GL_REV_CST_PL_ID.AsString();
                hidGL_ADJ_FEE_BS.Value = list[0].GL_ADJ_FEE_BS_ID.AsString();
                hidGL_REV_FEE_PL.Value = list[0].GL_REV_FEE_PL_ID.AsString();
                hidGL_SUBSEQ_ADJ_CST_BS.Value = list[0].GL_SUBSEQ_ADJ_CST_BS_ID.AsString();
                hidGL_SUBSEQ_ADJ_FEE_BS.Value = list[0].GL_SUBSEQ_ADJ_FEE_BS_ID.AsString();
                hidGL_IMP_LOSS_PL.Value = list[0].GL_IMP_LOSS_PL_ID.AsString();
                hidGL_ALLW_BAD_DEBT_PL.Value = list[0].GL_ALLW_BAD_DEBT_PL_ID.AsString();
                hidGL_WOFF_ADJ_FV_BS.Value = list[0].GL_WOFF_ADJ_FV_BS_ID.AsString();
                hidGL_WOFF_ADJ_FEE_BS.Value = list[0].GL_WOFF_ADJ_FEE_BS_ID.AsString();
                hidGL_WOFF_ADJ_CST_BS.Value = list[0].GL_WOFF_ADJ_CST_BS_ID.AsString();
                hidGL_DAY1_FV_LOSS_PL.Value = list[0].GL_DAY1_FV_LOSS_PL_ID.AsString();
                hidGL_DAY1_ADJ_FV_BS.Value = list[0].GL_DAY1_ADJ_FV_BS_ID.AsString();
                hidGL_WOFF_INT_DISC_LN.Value = list[0].GL_WOFF_INT_DISC_LN_ID.AsString();
                hidGL_DAY1_DEF_EXP_STAFF_BS.Value = list[0].GL_DAY1_DEF_EXP_STAFF_BS_ID.AsString();
                hidGL_AMC_EMP_CST_PL.Value = list[0].GL_AMC_EMP_CST_PL_ID.AsString();
                hidGL_AMC_DEF_EXP_STAFF_BS.Value = list[0].GL_AMC_DEF_EXP_STAFF_BS_ID.AsString();
                hidGL_SUBSIDY_INT_REC_BS.Value = list[0].GL_SUBSIDY_INT_REC_BS_ID.AsString();
                hidGL_SUBSIDY_INT_INC_PL.Value = list[0].GL_SUBSIDY_INT_INC_PL_ID.AsString();

                hidGL_LOSS_IMP_INV_PL.Value = list[0].GL_LOSS_IMP_INV_PL_ID.AsString();
                hidGL_COMMISSION.Value = list[0].GL_COMMISSION_ID.AsString();
                hidGL_INV_AMT_CHG.Value = list[0].GL_INV_AMT_CHG_ID.AsString();
                hidGL_DAY1_LOSS_PL.Value = list[0].GL_DAY1_LOSS_PL_ID.AsString();
                hidGL_CHG_UNREALIZED_AFS_PL.Value = list[0].GL_CHG_UNREALIZED_AFS_PL_ID.AsString();
                hidGL_ACCUM_FVTOCI_PL.Value = list[0].GL_ACCUM_FVTOCI_PL_ID.AsString();

                txtGL_ACCOUNT.Text = list[0].GLAccount_CODE;
                txtGL_ADJ_INT_INC_PL.Text = list[0].GL_ADJ_INT_INC_PL_CODE;
                txtGL_ADJ_FV_BS.Text = list[0].GL_ADJ_FV_BS_CODE;
                txtGL_ADJ_INT_INC_ELCLS_PL.Text = list[0].GL_ADJ_INT_INC_ELCLS_PL_CODE;
                txtGL_ADJ_CST_BS.Text = list[0].GL_ADJ_CST_BS_CODE;
                txtGL_REV_CST_PL.Text = list[0].GL_REV_CST_PL_CODE;
                txtGL_ADJ_FEE_BS.Text = list[0].GL_ADJ_FEE_BS_CODE;
                txtGL_REV_FEE_PL.Text = list[0].GL_REV_FEE_PL_CODE;
                txtGL_SUBSEQ_ADJ_CST_BS.Text = list[0].GL_SUBSEQ_ADJ_CST_BS_CODE;
                txtGL_SUBSEQ_ADJ_FEE_BS.Text = list[0].GL_SUBSEQ_ADJ_FEE_BS_CODE;
                txtGL_IMP_LOSS_PL.Text = list[0].GL_IMP_LOSS_PL_CODE;
                txtGL_ALLW_BAD_DEBT_PL.Text = list[0].GL_ALLW_BAD_DEBT_PL_CODE;
                txtGL_WOFF_ADJ_FV_BS.Text = list[0].GL_WOFF_ADJ_FV_BS_CODE;
                txtGL_WOFF_ADJ_FEE_BS.Text = list[0].GL_WOFF_ADJ_FEE_BS_CODE;
                txtGL_WOFF_ADJ_CST_BS.Text = list[0].GL_WOFF_ADJ_CST_BS_CODE;
                txtGL_DAY1_FV_LOSS_PL.Text = list[0].GL_DAY1_FV_LOSS_PL_CODE;
                txtGL_DAY1_ADJ_FV_BS.Text = list[0].GL_DAY1_ADJ_FV_BS_CODE;
                txtGL_WOFF_INT_DISC_LN.Text = list[0].GL_WOFF_INT_DISC_LN_CODE;
                txtGL_DAY1_DEF_EXP_STAFF_BS.Text = list[0].GL_DAY1_DEF_EXP_STAFF_BS_CODE;
                txtGL_AMC_EMP_CST_PL.Text = list[0].GL_AMC_EMP_CST_PL_CODE;
                txtGL_AMC_DEF_EXP_STAFF_BS.Text = list[0].GL_AMC_DEF_EXP_STAFF_BS_CODE;
                txtGL_SUBSIDY_INT_REC_BS.Text = list[0].GL_SUBSIDY_INT_REC_BS_CODE;
                txtGL_SUBSIDY_INT_INC_PL.Text = list[0].GL_SUBSIDY_INT_INC_PL_CODE;

                txtGL_LOSS_IMP_INV_PL.Text = list[0].GL_LOSS_IMP_INV_PL_CODE;
                txtGL_COMMISSION.Text = list[0].GL_COMMISSION_CODE;
                txtGL_INV_AMT_CHG.Text = list[0].GL_INV_AMT_CHG_CODE;
                txtGL_DAY1_LOSS_PL.Text = list[0].GL_DAY1_LOSS_PL_CODE;
                txtGL_CHG_UNREALIZED_AFS_PL.Text = list[0].GL_CHG_UNREALIZED_AFS_PL_CODE;
                txtGL_ACCUM_FVTOCI_PL.Text = list[0].GL_ACCUM_FVTOCI_PL_CODE;

                txtGLGroup_ID.Text = list[0].GLGroup_NAME;
                txtGL_ACCOUNT_NAME.Text = list[0].GLAccount_NAME;
                txtGL_ADJ_INT_INC_PL_NAME.Text = list[0].GL_ADJ_INT_INC_PL_NAME;
                txtGL_ADJ_FV_BS_NAME.Text = list[0].GL_ADJ_FV_BS_NAME;
                txtGL_ADJ_INT_INC_ELCLS_PL_NAME.Text = list[0].GL_ADJ_INT_INC_ELCLS_PL_NAME;
                txtGL_ADJ_CST_BS_NAME.Text = list[0].GL_ADJ_CST_BS_NAME;
                txtGL_REV_CST_PL_NAME.Text = list[0].GL_REV_CST_PL_NAME;
                txtGL_ADJ_FEE_BS_NAME.Text = list[0].GL_ADJ_FEE_BS_NAME;
                txtGL_REV_FEE_PL_NAME.Text = list[0].GL_REV_FEE_PL_NAME;
                txtGL_SUBSEQ_ADJ_CST_BS_NAME.Text = list[0].GL_SUBSEQ_ADJ_CST_BS_NAME;
                txtGL_SUBSEQ_ADJ_FEE_BS_NAME.Text = list[0].GL_SUBSEQ_ADJ_FEE_BS_NAME;
                txtGL_IMP_LOSS_PL_NAME.Text = list[0].GL_IMP_LOSS_PL_NAME;
                txtGL_ALLW_BAD_DEBT_PL_NAME.Text = list[0].GL_ALLW_BAD_DEBT_PL_NAME;
                txtGL_WOFF_ADJ_FV_BS_NAME.Text = list[0].GL_WOFF_ADJ_FV_BS_NAME;
                txtGL_WOFF_ADJ_FEE_BS_NAME.Text = list[0].GL_WOFF_ADJ_FEE_BS_NAME;
                txtGL_WOFF_ADJ_CST_BS_NAME.Text = list[0].GL_WOFF_ADJ_CST_BS_NAME;
                txtGL_DAY1_FV_LOSS_PL_NAME.Text = list[0].GL_DAY1_FV_LOSS_PL_NAME;
                txtGL_DAY1_ADJ_FV_BS_NAME.Text = list[0].GL_DAY1_ADJ_FV_BS_NAME;
                txtGL_WOFF_INT_DISC_LN_NAME.Text = list[0].GL_WOFF_INT_DISC_LN_NAME;
                txtGL_DAY1_DEF_EXP_STAFF_BS_NAME.Text = list[0].GL_DAY1_DEF_EXP_STAFF_BS_NAME;
                txtGL_AMC_EMP_CST_PL_NAME.Text = list[0].GL_AMC_EMP_CST_PL_NAME;
                txtGL_AMC_DEF_EXP_STAFF_BS_NAME.Text = list[0].GL_AMC_DEF_EXP_STAFF_BS_NAME;
                txtGL_SUBSIDY_INT_REC_BS_NAME.Text = list[0].GL_SUBSIDY_INT_REC_BS_NAME;
                txtGL_SUBSIDY_INT_INC_PL_NAME.Text = list[0].GL_SUBSIDY_INT_INC_PL_NAME;


                txtGL_LOSS_IMP_INV_PL_NAME.Text = list[0].GL_LOSS_IMP_INV_PL_NAME;
                txtGL_COMMISSION_NAME.Text = list[0].GL_COMMISSION_NAME;
                txtGL_INV_AMT_CHG_NAME.Text = list[0].GL_INV_AMT_CHG_NAME;
                txtGL_DAY1_LOSS_PL_NAME.Text = list[0].GL_DAY1_LOSS_PL_NAME;
                txtGL_CHG_UNREALIZED_AFS_PL_NAME.Text = list[0].GL_CHG_UNREALIZED_AFS_PL_NAME;
                txtGL_ACCUM_FVTOCI_PL_NAME.Text = list[0].GL_ACCUM_FVTOCI_PL_NAME;
            }
        }
    }
    private void SaveData()
    {

        try
        {
            GLAccountPosting vGLAccountPosting = new GLAccountPosting();
            vGLAccountPosting.GLAccountPostingID = hidGLAccountPostingID.Value.AsInt32();
            vGLAccountPosting.GLGroupID = hidGLGroup_ID.Value.AsIntIsnull();//txtTransactionDate.Text.StringToDateAllowNull();
            vGLAccountPosting.GLAccountID = hidGL_ACCOUNT.Value.AsIntIsnull();//ddlSource_data.SelectedValue.AsInt32();
            vGLAccountPosting.GL_ADJ_INT_INC_PL_ID = hidGL_ADJ_INT_INC_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_ADJ_FV_BS_ID = hidGL_ADJ_FV_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_ADJ_INT_INC_ELCLS_PL_ID = hidGL_ADJ_INT_INC_ELCLS_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_ADJ_CST_BS_ID = hidGL_ADJ_CST_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_REV_CST_PL_ID = hidGL_REV_CST_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_ADJ_FEE_BS_ID = hidGL_ADJ_FEE_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_REV_FEE_PL_ID = hidGL_REV_FEE_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_SUBSEQ_ADJ_CST_BS_ID = hidGL_SUBSEQ_ADJ_CST_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_SUBSEQ_ADJ_FEE_BS_ID = hidGL_SUBSEQ_ADJ_FEE_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_IMP_LOSS_PL_ID = hidGL_IMP_LOSS_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_ALLW_BAD_DEBT_PL_ID = hidGL_ALLW_BAD_DEBT_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_WOFF_ADJ_FV_BS_ID = hidGL_WOFF_ADJ_FV_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_WOFF_ADJ_FEE_BS_ID = hidGL_WOFF_ADJ_FEE_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_WOFF_ADJ_CST_BS_ID = hidGL_WOFF_ADJ_CST_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_DAY1_FV_LOSS_PL_ID = hidGL_DAY1_FV_LOSS_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_DAY1_ADJ_FV_BS_ID = hidGL_DAY1_ADJ_FV_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_WOFF_INT_DISC_LN_ID = hidGL_WOFF_INT_DISC_LN.Value.AsIntIsnull();
            vGLAccountPosting.GL_DAY1_DEF_EXP_STAFF_BS_ID = hidGL_DAY1_DEF_EXP_STAFF_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_AMC_EMP_CST_PL_ID = hidGL_AMC_EMP_CST_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_AMC_DEF_EXP_STAFF_BS_ID = hidGL_AMC_DEF_EXP_STAFF_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_SUBSIDY_INT_REC_BS_ID = hidGL_SUBSIDY_INT_REC_BS.Value.AsIntIsnull();
            vGLAccountPosting.GL_SUBSIDY_INT_INC_PL_ID = hidGL_SUBSIDY_INT_INC_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_LOSS_IMP_INV_PL_ID = hidGL_LOSS_IMP_INV_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_COMMISSION_ID = hidGL_COMMISSION.Value.AsIntIsnull();
            vGLAccountPosting.GL_INV_AMT_CHG_ID = hidGL_INV_AMT_CHG.Value.AsIntIsnull();
            vGLAccountPosting.GL_DAY1_LOSS_PL_ID = hidGL_DAY1_LOSS_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_CHG_UNREALIZED_AFS_PL_ID = hidGL_CHG_UNREALIZED_AFS_PL.Value.AsIntIsnull();
            vGLAccountPosting.GL_ACCUM_FVTOCI_PL_ID = hidGL_ACCUM_FVTOCI_PL.Value.AsIntIsnull();
            vGLAccountPosting.SetStandardField();

            int iID = 0;
            var SPR_GLACCOUNTPOSTING = new SPR_GLACCOUNTPOSTING();
            iID = SPR_GLACCOUNTPOSTING.UPDATE(vGLAccountPosting);
            if (iID > 0)
            {

                this.JS_Alert(Resources.ifrsResource.SaveData, ResolveUrl(string.Format("~/IFRS/WIN31_GL_INV_2E.aspx?&id={0}", hidGLAccountPostingID.Value)));
            }
            else
            {
                if (iID == -1)
                {
                    Utility.AlertMessage(Page, Resources.ifrsResource.Duplicate);
                }
                else
                {
                    Utility.AlertMessage(Page, Resources.ifrsResource.CanNotSaveData);
                }

            }

        }
        catch (Exception ex)
        {
            throw ex;
        }

    }
    #endregion
 
}